package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            String sql = "select t.name,t.salary,c.name,c.floor "+
                        " from teacher t "+
                         "join class c on c.teacher_id=t.id "+
                         "where t.name='王克晶' ";
            ResultSet re = statement.executeQuery(sql);
            while (re.next()){
                String name = re.getString("t.name");
                int salary = re.getInt("t.salary");
                String class_name = re.getString("c.name");
                int floor = re.getInt("c.floor");
                //System.out.println(name+" "+salary+" "+class_name+" "+floor);
                //String 提供了一个方法 join() 将字符串数组中的元素用指定的分隔符连接起来 第一个参数为分隔符 第二个参数为字符串数组
                String line = String.join(",",name,salary+"",class_name,floor+"");//拼接字符串 返回字符串
                System.out.println(line);
            }
        } catch (SQLException e) {
           e.printStackTrace();
        }
    }
}
